package org.example.sortdemo;

/**
 * @author: knowno
 * @create: 2025-09-10 10:06
 * @Version 1.0
 * 冒泡排序
 **/
public class MaopaoSort {
    public static void main(String[] args) {
        int arrs[]={4,6,5,3,7,1,8,2};//初始数组
        int tempData=0;//数组元素对调时用来存放旧值
        for(int i=0;i<arrs.length;i++){
            for(int j=0;j<arrs.length-i-1;j++){
                if(arrs[j]>arrs[j+1]){
                    tempData=arrs[j];
                    arrs[j]=arrs[j+1];
                    arrs[j+1]=tempData;
                }
            }
            System.out.println("第"+(i+1)+"轮排序结果:");
            for (int k:arrs){
                System.out.println(k);
            }
        }

    }
}
